package com.example.zzl.view.fragment.ShareOrderFragment.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.zzl.R;
import com.example.zzl.view.fragment.ShareOrderFragment.fragment.MyListView;
import com.example.zzl.view.fragment.ShareOrderFragment.model.User;

import java.util.ArrayList;
import java.util.List;

import jp.wasabeef.glide.transformations.CropCircleTransformation;


/**
 * Created by Administrator on 2017/2/10.
 */
public class PoplvAdapter extends BaseAdapter{
    private Context context;
    private List<User.InfolistBean> list;
    private PopAdapter adapter;
    private List<User.InfolistBean.ReviewinfolistBean> olist;
    private RelativeLayout r;

    public PoplvAdapter(Context context, List<User.InfolistBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        olist=new ArrayList<>();
        final ViewHolder vh;
        if (convertView == null) {
            vh=new ViewHolder();
            convertView = View.inflate(context, R.layout.suipian, null);

r=(RelativeLayout)convertView.findViewById(R.id.texiao);
//            RelativeLayout.LayoutParams p= (RelativeLayout.LayoutParams)r.getLayoutParams();
//        p.height=0;
//        r.setLayoutParams(p);

            vh.tv_author_name = (TextView) convertView.findViewById(R.id.share_autor_name);
            vh.tv_createtime = (TextView) convertView.findViewById(R.id.share_autor_createtime);
            vh.tv_show_num = (TextView) convertView.findViewById(R.id.fenmu);
            vh.tv_show_neirong = (TextView) convertView.findViewById(R.id.show_neirong);
            vh.tv_x_tiaopinglun = (TextView) convertView.findViewById(R.id.xtiao);
            vh.tv_xiangguan_jieshao = (TextView) convertView.findViewById(R.id.share_thing_ieshao);
            vh.tv_xiangguan_jiage = (TextView) convertView.findViewById(R.id.share_jiage);
            vh.tv_shoucang = (TextView) convertView.findViewById(R.id.share_dianzan);

            vh.tv_chakan = (TextView) convertView.findViewById(R.id.bu1);

            vh.listView=(MyListView)convertView.findViewById(R.id.pinglv);

            vh.iv_author_img = (ImageView) convertView.findViewById(R.id.share_autor_img);
            vh.iv_show = (ImageView) convertView.findViewById(R.id.show);
            vh.iv_xiangguan = (ImageView) convertView.findViewById(R.id.share_thing_img);


            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        vh.tv_chakan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (vh.tv_chakan.getText().equals("查看全文")){
                    vh.tv_chakan.setText("收起");
                    vh.tv_chakan.setMaxLines(20);
                }else if(vh.tv_chakan.getText().equals("收起")){
                    vh.tv_chakan.setText("查看全文");
                    vh.tv_chakan.setMaxLines(6);
                }
            }
        });


        //  vh.tv_show_neirong.setOnClickListener(this);

        vh.tv_author_name.setText(list.get(position).NickName);
        vh.tv_createtime.setText(list.get(position).UpdateTime);
        int size = list.get(position).ImageTags.size();

        vh.tv_show_num.setText(size+"");

        vh.tv_show_neirong.setText(list.get(position).InfoContent);


        vh.tv_x_tiaopinglun.setText(list.get(position).CommentCount+"");

        vh.tv_xiangguan_jieshao.setText(list.get(position).InfoTitle);
        if ((int)list.get(position).MinPriceRMB==(int)list.get(position).MaxPriceRMB) {
            vh.tv_xiangguan_jiage.setText((int)list.get(position).MaxPriceRMB+"");
        }else if ((int)list.get(position).MinPriceRMB!=(int)list.get(position).MaxPriceRMB){
            vh.tv_xiangguan_jiage.setText((int)list.get(position).MinPriceRMB+"~"+(int)list.get(position).MaxPriceRMB);
        }
        String praiseGoodCount = list.get(position).PraiseGoodCount + "";
//        if (praiseGoodCount.length()>0){
        vh.tv_shoucang.setText(list.get(position).PraiseGoodCount+"");

        // final BitmapPool bitmapPool = Glide.get(context).getBitmapPool();

        Glide.with(context).load(list.get(position).HeadImage).bitmapTransform(new CropCircleTransformation(context)).into(vh.iv_author_img);



        Glide.with(context).load(list.get(position).MainImage).into(vh.iv_show);
        RelativeLayout.LayoutParams p= (RelativeLayout.LayoutParams) vh.iv_show.getLayoutParams();
        p.height=vh.iv_show.getWidth();
        vh.iv_show.setLayoutParams(p);
        Glide.with(context).load(list.get(position).MainImage).into(vh.iv_xiangguan);

        olist.addAll(list.get(position).reviewinfolist);
        adapter=new PopAdapter(context,olist);
        vh.listView.setAdapter(adapter);

        return convertView;
    }
    class  ViewHolder{

        TextView tv_author_name, tv_createtime, tv_show_num, tv_show_neirong, tv_x_tiaopinglun,
                tv_xiangguan_jieshao, tv_xiangguan_jiage, tv_shoucang, tv_chakan;
        ImageView iv_author_img, iv_show, iv_xiangguan;
        MyListView listView;

    }
}
